//
//  ZXXMainViewController.swift
//  M-Weibo
//
//  Created by ZXX on 16/4/18.
//  Copyright © 2016年 ZXX. All rights reserved.
//

import UIKit


// MARK: - CZTabBarDelegate
// extension 相当于我们OC中的分类 extension 后面的类 CZMainViewController 就代表是当前类的分类
extension ZXXMainViewController: ZXXTabBarDelegate{
    func composeButtonClick(){
//        print("撰写按钮实现了")
        let controller = ZXXComposeController()
        presentViewController(UINavigationController(rootViewController: controller), animated: true, completion: nil)
    }
}


class ZXXMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // 初始化tabbar
        let tabbar = ZXXTabBar()
//        设置代理
        tabbar.zxxTabBarDelegate = self
        
//        kvc赋值  
        // self.tabBar  系统私有属性 不能直接设置
        setValue(tabbar, forKey: "tabBar")
        
        
//       添加子控制器
        addChildViewController(ZXXHomeController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(ZXXDiscoverController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(ZXXMessageController(), imageName: "tabbar_message_center", title: "信息")
        addChildViewController(ZXXProfileController(), imageName: "tabbar_profile", title: "我的")
        
    }
    // MARK: -  添加子控制器的方法
    func addChildViewController(childController: UIViewController, imageName: String, title: String) {
        
        
        childController.tabBarItem.image = UIImage(named: "\(imageName)")
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")
        childController.title = title
        addChildViewController(UINavigationController(rootViewController: childController))
    }
    
    
    
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
